<template>
    <LModalForm 
        :visible="visible"
        :confirmLoading="confirmLoading" 
        :title="title" 
        ref="attribute" 
        :formAttributes="formAttributes" 
        @handleOk="handleOk" 
        @handleCancel="handleCancel"
        @clickEventHandler="clickEventHandler"
        @changeEventHandler="changeEventHandler"></LModalForm>

</template>

<script>
import LModalForm from "@/components/lt/form/LModalForm"
import pageSetting from '@/components/lt/codeGenerator/pageSetting'
import pick from 'lodash.pick'
import defaultSettings from '@/config/defaultSettings'


export default {
    name:'TableColumnAttribute',
    components:{
        LModalForm
    },
    data(){
        return{
            pageSetting,
            title:'详情',
            visible:false,
            confirmLoading: false,
            model:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'title',label:'标题',component:pageSetting.常量.表单组件类型.单行文本,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'dataIndex',label:'字段代码',component:pageSetting.常量.表单组件类型.单行文本,disabled:true,rules: [{ required: true, message: '不能为空!' }]},
                    {field:'entityClassName',label:'实体名称',component:pageSetting.常量.表单组件类型.单行文本,disabled:true},
                    {field:'dbField',label:'数据库字段',component:pageSetting.常量.表单组件类型.单行文本,disabled:true},
                    {field:'width',label:'宽',component:pageSetting.常量.表单组件类型.单行文本},
                    {field:'sorter',label:'是否排序',component:pageSetting.常量.表单组件类型.开关,checkedChildren:true,unCheckedChildren:false},
                    {field:'selecter',label:'是否下拉',component:pageSetting.常量.表单组件类型.开关,checkedChildren:true,unCheckedChildren:false},
                    {field:'dictCode',label:'数据字典',component:pageSetting.常量.表单组件类型.下拉选择,dictCode:defaultSettings.数据字典.数据字典名称,rules: [{ required: true, message: '不能为空!' }]},
       
                 ]
                },
              ]

            }


        }
    },
    methods:{
       
        edit (record) {
            this.visible = true
            this.model=record
            this.$nextTick(() => {
                this.$refs.attribute.getForm().setFieldsValue(pick(this.model,'title','dataIndex','width','sorter','selecter','dictCode','entityClassName','dbField'))
                this.formAttributes.formItems[0].fields[7].rules[0].required=this.model.selecter || false
            })
            
        },
        handleOk(){
            this.$refs.attribute.getForm().validateFields((err, values) => {
                if (!err) {
                    this.model = Object.assign(this.model, values)
                    delete this.model['scopedSlots']
                    if(this.model['selecter'] && this.model['dictCode']){
                        this.model["scopedSlots"] = { customRender: this.model.dataIndex }
                    }
                    this.close()
                }
            })
            
        },
        handleCancel(){
            this.visible=false
        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
       
        /**
         * 表单内容发生变化
         */
        changeEventHandler(changeItem){
            if(changeItem.hasOwnProperty('selecter')){
                this.formAttributes.formItems[0].fields[7].rules[0].required=changeItem.selecter
            }
            
        },
        clickEventHandler(field,form){
            
        }
    },
    created(){
        
    },
}
</script>